@extends('admin.layouts.ui')
@section('title','后台管理欢迎页面')
@section('content')
    <!-- 模态框（Modal） -->
    <div class="row">
        <div class="card">
            <div class="card-body">
                {!! Form::model($give,['route' => ['give.update',$give->id], 'method' => 'PATCH','id' =>'form']) !!}
                <div class="form-row">

                    <div class="form-group col-lg-6">
                        <label for="firstname">名称</label>
                        <input type="text" value="{{ $give->name }}" name="name" class="form-control" id="firstname">
                    </div>
                    <div class="form-group col-lg-12 text-righ">
                        <button type="submit" class="btn btn-common ml-5">修改</button>
                    </div>
                </div>
                {!! Form::close() !!}
            </div>
        </div>
    </div>
@stop
@section('js')
    <script type="text/javascript">
        $('#form').Validform({
            tiptype : 4,
            ajaxPost : true,
            beforeCheck:function(curform){
                console.log(curform);
                //在表单提交执行验证之前执行的函数，curform参数是当前表单对象。
                //这里明确return false的话将不会继续执行验证操作;
                index = layer.load(1, {shade: [0.6, '#393D49']});
            },
            callback : function (res) {
                console.log(res);
                if(res.status == 422) {
                    var json=JSON.parse(res.responseText);
                    $.each(json.errors, function(idx, obj) {
                        layer.msg(obj[0], {icon: 5});
                        layer.close(index);
                        return false;
                    });
                } else if(res.status== 200) {
                    layer.msg(res.msg, {
                        icon: 1,
                        time: 2000 //2秒关闭（如果不配置，默认是3秒）
                    }, function(){
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                        parent.location.href = '{{ route('give.index') }}'
                    });

                }
            },
        });
    </script>
@stop
